<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>transition.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_style_transition.js.html">transition.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2011 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Utility methods to deal with CSS3 transitions
<a name="line17"></a> * programmatically.
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.style.transition&#39;);
<a name="line21"></a>goog.provide(&#39;goog.style.transition.Css3Property&#39;);
<a name="line22"></a>
<a name="line23"></a>goog.require(&#39;goog.array&#39;);
<a name="line24"></a>goog.require(&#39;goog.asserts&#39;);
<a name="line25"></a>goog.require(&#39;goog.dom.vendor&#39;);
<a name="line26"></a>goog.require(&#39;goog.style&#39;);
<a name="line27"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line28"></a>
<a name="line29"></a>
<a name="line30"></a>/**
<a name="line31"></a> * A typedef to represent a CSS3 transition property. Duration and delay
<a name="line32"></a> * are both in seconds. Timing is CSS3 timing function string, such as
<a name="line33"></a> * &#39;easein&#39;, &#39;linear&#39;.
<a name="line34"></a> *
<a name="line35"></a> * Alternatively, specifying string in the form of &#39;[property] [duration]
<a name="line36"></a> * [timing] [delay]&#39; as specified in CSS3 transition is fine too.
<a name="line37"></a> *
<a name="line38"></a> * @typedef { {
<a name="line39"></a> *   property: string,
<a name="line40"></a> *   duration: number,
<a name="line41"></a> *   timing: string,
<a name="line42"></a> *   delay: number
<a name="line43"></a> * } | string }
<a name="line44"></a> */
<a name="line45"></a>goog.style.transition.Css3Property;
<a name="line46"></a>
<a name="line47"></a>
<a name="line48"></a>/**
<a name="line49"></a> * Sets the element CSS3 transition to properties.
<a name="line50"></a> * @param {Element} element The element to set transition on.
<a name="line51"></a> * @param {goog.style.transition.Css3Property|
<a name="line52"></a> *     Array.&lt;goog.style.transition.Css3Property&gt;} properties A single CSS3
<a name="line53"></a> *     transition property or array of properties.
<a name="line54"></a> */
<a name="line55"></a>goog.style.transition.set = function(element, properties) {
<a name="line56"></a>  if (!goog.isArray(properties)) {
<a name="line57"></a>    properties = [properties];
<a name="line58"></a>  }
<a name="line59"></a>  goog.asserts.assert(
<a name="line60"></a>      properties.length &gt; 0, &#39;At least one Css3Property should be specified.&#39;);
<a name="line61"></a>
<a name="line62"></a>  var values = goog.array.map(
<a name="line63"></a>      properties, function(p) {
<a name="line64"></a>        if (goog.isString(p)) {
<a name="line65"></a>          return p;
<a name="line66"></a>        } else {
<a name="line67"></a>          goog.asserts.assertObject(p,
<a name="line68"></a>              &#39;Expected css3 property to be an object.&#39;);
<a name="line69"></a>          var propString = p.property + &#39; &#39; + p.duration + &#39;s &#39; + p.timing +
<a name="line70"></a>              &#39; &#39; + p.delay + &#39;s&#39;;
<a name="line71"></a>          goog.asserts.assert(p.property &amp;&amp; goog.isNumber(p.duration) &amp;&amp;
<a name="line72"></a>              p.timing &amp;&amp; goog.isNumber(p.delay),
<a name="line73"></a>              &#39;Unexpected css3 property value: %s&#39;, propString);
<a name="line74"></a>          return propString;
<a name="line75"></a>        }
<a name="line76"></a>      });
<a name="line77"></a>  goog.style.transition.setPropertyValue_(element, values.join(&#39;,&#39;));
<a name="line78"></a>};
<a name="line79"></a>
<a name="line80"></a>
<a name="line81"></a>/**
<a name="line82"></a> * Removes any programmatically-added CSS3 transition in the given element.
<a name="line83"></a> * @param {Element} element The element to remove transition from.
<a name="line84"></a> */
<a name="line85"></a>goog.style.transition.removeAll = function(element) {
<a name="line86"></a>  goog.style.transition.setPropertyValue_(element, &#39;&#39;);
<a name="line87"></a>};
<a name="line88"></a>
<a name="line89"></a>
<a name="line90"></a>/**
<a name="line91"></a> * @return {boolean} Whether CSS3 transition is supported.
<a name="line92"></a> */
<a name="line93"></a>goog.style.transition.isSupported = function() {
<a name="line94"></a>  if (!goog.isDef(goog.style.transition.css3TransitionSupported_)) {
<a name="line95"></a>    // Since IE would allow any attribute, we need to explicitly check the
<a name="line96"></a>    // browser version here instead.
<a name="line97"></a>    if (goog.userAgent.IE) {
<a name="line98"></a>      goog.style.transition.css3TransitionSupported_ =
<a name="line99"></a>          goog.userAgent.isVersion(&#39;10.0&#39;);
<a name="line100"></a>    } else {
<a name="line101"></a>      // We create a test element with style=-vendor-transition
<a name="line102"></a>      // We then detect whether those style properties are recognized and
<a name="line103"></a>      // available from js.
<a name="line104"></a>      var el = document.createElement(&#39;div&#39;);
<a name="line105"></a>      var transition = &#39;transition:opacity 1s linear;&#39;;
<a name="line106"></a>      var vendorPrefix = goog.dom.vendor.getVendorPrefix();
<a name="line107"></a>      var vendorTransition =
<a name="line108"></a>          vendorPrefix ? vendorPrefix + &#39;-&#39; + transition : &#39;&#39;;
<a name="line109"></a>      el.innerHTML = &#39;&lt;div style=&quot;&#39; + vendorTransition + transition + &#39;&quot;&gt;&#39;;
<a name="line110"></a>
<a name="line111"></a>      var testElement = /** @type {Element} */ (el.firstChild);
<a name="line112"></a>      goog.asserts.assert(testElement.nodeType == Node.ELEMENT_NODE);
<a name="line113"></a>
<a name="line114"></a>      goog.style.transition.css3TransitionSupported_ =
<a name="line115"></a>          goog.style.getStyle(testElement, &#39;transition&#39;) != &#39;&#39;;
<a name="line116"></a>    }
<a name="line117"></a>  }
<a name="line118"></a>  return goog.style.transition.css3TransitionSupported_;
<a name="line119"></a>};
<a name="line120"></a>
<a name="line121"></a>
<a name="line122"></a>/**
<a name="line123"></a> * Whether CSS3 transition is supported.
<a name="line124"></a> * @type {boolean}
<a name="line125"></a> * @private
<a name="line126"></a> */
<a name="line127"></a>goog.style.transition.css3TransitionSupported_;
<a name="line128"></a>
<a name="line129"></a>
<a name="line130"></a>/**
<a name="line131"></a> * Sets CSS3 transition property value to the given value.
<a name="line132"></a> * @param {Element} element The element to set transition on.
<a name="line133"></a> * @param {string} transitionValue The CSS3 transition property value.
<a name="line134"></a> * @private
<a name="line135"></a> */
<a name="line136"></a>goog.style.transition.setPropertyValue_ = function(element, transitionValue) {
<a name="line137"></a>  goog.style.setStyle(element, &#39;transition&#39;, transitionValue);
<a name="line138"></a>};
</pre>


</body>
</html>
